package lp.xian.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.domain.SupplierGoods;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.equipment.service.ISupplierGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品详情Controller
 *
 * @author ruoyi
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/suppliergoods/suppliergoods")
public class SupplierGoodsController extends BaseController
{
    @Autowired
    private ISupplierGoodsService supplierGoodsService;

    /**
     * 查询商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierGoods supplierGoods)
    {
        startPage();
        List<SupplierGoods> list = supplierGoodsService.selectSupplierGoodsList(supplierGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:export')")
    @Log(title = "商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierGoods supplierGoods)
    {
        List<SupplierGoods> list = supplierGoodsService.selectSupplierGoodsList(supplierGoods);
        ExcelUtil<SupplierGoods> util = new ExcelUtil<SupplierGoods>(SupplierGoods.class);
        util.exportExcel(response, list, "商品详情数据");
    }

    /**
     * 获取商品详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:query')")
    @GetMapping(value = "/{supplierGoodsId}")
    public AjaxResult getInfo(@PathVariable("supplierGoodsId") Integer supplierGoodsId)
    {
        return success(supplierGoodsService.selectSupplierGoodsBySupplierGoodsId(supplierGoodsId));
    }

    /**
     * 新增商品详情
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:add')")
    @Log(title = "商品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierGoods supplierGoods)
    {
        return toAjax(supplierGoodsService.insertSupplierGoods(supplierGoods));
    }

    /**
     * 修改商品详情
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:edit')")
    @Log(title = "商品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierGoods supplierGoods)
    {
        return toAjax(supplierGoodsService.updateSupplierGoods(supplierGoods));
    }

    /**
     * 删除商品详情
     */
    @PreAuthorize("@ss.hasPermi('suppliergoods:suppliergoods:remove')")
    @Log(title = "商品详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierGoodsIds}")
    public AjaxResult remove(@PathVariable Integer[] supplierGoodsIds)
    {
        return toAjax(supplierGoodsService.deleteSupplierGoodsBySupplierGoodsIds(supplierGoodsIds));
    }
}
